home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Misc / emu / p-interp.lha / p-interp-0.5 / native6502.c < prev    next >
C/C++ Source or Header  |  2001-06-10  |  17KB  |  442 lines

  1. /*
  2.  
  3.   P-Code interpreter (to run the apple pascal system)
  4.   Copyright (C) 2000 Mario Klebsch
  5.  
  6.   This program is free software; you can redistribute it and/or modify
  7.   it under the terms of the GNU General Public License as published by
  8.   the Free Software Foundation; either version 2 of the License, or
  9.   (at your option) any later version.
  10.  
  11.   This program is distributed in the hope that it will be useful,
  12.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.   GNU General Public License for more details.
  15.  
  16.   You should have received a copy of the GNU General Public License
  17.   along with this program; if not, write to the Free Software
  18.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20.  
  21.   $Log: native6502.c,v $
  22.   Revision 1.5  2001/06/10 20:40:04  mario
  23.   Long integers mit BCD-Arithmetic implementiert, Divisionsroutine fehlt noch.
  24.  
  25.   Revision 1.4  2001/06/06 23:14:19  mario
  26.   Turtlegraphics wird jetzt mit einem #define aktiviert
  27.  
  28.   Revision 1.3  2001/05/26 15:13:29  mario
  29.   Diverse kleine Fehler behoben, fehlende #includes, Labels ohne Statement
  30.   dahinter, ...
  31.  
  32.   Revision 1.2  2001/05/20 13:12:02  mario
  33.   CVS-Idents und Logs eingefügt
  34.  
  35.  
  36. */
  37.  
  38. #ident "$Id: native6502.c,v 1.5 2001/06/10 20:40:04 mario Exp $";
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <time.h>
  43.  
  44. #include "psystem.h"
  45. #include "pcode.h"
  46. #include "Memory.h"
  47. #include "Array.h"
  48. #include "Term.h"
  49.  
  50. static void IdSearch(word EntryPoint)
  51. {
  52.   word    BufPtr    = Pop();
  53.   word    Arg2Ptr   = Pop();
  54.  
  55.   CspIdSearch(BufPtr, Arg2Ptr);
  56. }
  57.  
  58. static byte IdSearchSig[]=
  59. { 0x68, 0x85, 0x7e, 0x68, 0x85, 0x7f, 0x68, 0xa8, 0x68, 0xaa,
  60.   0x68, 0x85, 0x94, 0x68, 0x85, 0x95, 0x98, 0xa0, 0x00, 0x18,
  61.   0x71, 0x94, 0x85, 0x96, 0x8a, 0xc8, 0x71, 0x94, 0x85, 0x97,
  62.   0xa9, 0x20, 0xa2, 0x07, 0x95, 0x88, 0xca, 0xd0, 0xfb, 0x88,
  63.   0xb1, 0x96, 0xc9, 0x61, 0x90, 0x07, 0xc9, 0x7b, 0xb0, 0x03 };
  64.  
  65. static void TreeSearch(word EntryPoint)
  66. {
  67.   word    TokenBuf;
  68.   word    ResultPtr;
  69.   word    NodePtr;
  70.  
  71.   Pop(); Pop();
  72.   TokenBuf  = Pop();
  73.   ResultPtr = Pop();
  74.   NodePtr   = Pop();            /* initialize with root node addr   */
  75.  
  76.   Push(CspTreeSearch(TokenBuf, ResultPtr, NodePtr));
  77. }
  78.  
  79. static void Randomize(word EntryPoint)
  80. {
  81.   srand(time(0L));
  82. }
  83.  
  84. static byte RandomizeSig1[]=
  85. { 0xad, 0x13, 0xbf, 0x8d, 0x3f, 0x02, 0x8d, 0x40,
  86.   0x02, 0xad, 0x14, 0xbf, 0x8d, 0x41, 0x02, 0x8d,
  87.   0x42, 0x02, 0x0d, 0x3f, 0x02, 0xd0, 0x05, 0xa9,
  88.   0x55, 0x8d, 0x42, 0x02, 0x60, 0x00, 0x00, 0x00,
  89.   0x00, 0x00, 0x1e, 0x00, 0x1d, 0x00, 0x19, 0x00,
  90.   0x18, 0x00, 0x17, 0x00, 0x12, 0x00, 0x06, 0x00,
  91.   0x00, 0x00, 0x32, 0x00 };
  92.  
  93. static byte RandomizeSig2[]=
  94. { 0xad, 0x13, 0xbf, 0x8d, 0x25, 0x02, 0x8d, 0x26,
  95.   0x02, 0xad, 0x14, 0xbf, 0x8d, 0x27, 0x02, 0x8d,
  96.   0x28, 0x02, 0x0d, 0x25, 0x02, 0xd0, 0x05, 0xa9,
  97.   0x55, 0x8d, 0x28, 0x02, 0x60, 0x00, 0x00, 0x00,
  98.   0x00, 0x00, 0x1e, 0x00, 0x1d, 0x00, 0x19, 0x00,
  99.   0x18, 0x00, 0x17, 0x00, 0x12, 0x00, 0x06, 0x00,
  100.   0x00, 0x00, 0x32, 0x00 };
  101.  
  102. static void Keypress(word EntryPoint)
  103. {
  104.   Pop();
  105.   Pop();
  106.   Push(TermStat());
  107. }
  108.  
  109. static byte KeypressSig[]=
  110. {  0x68, 0x85, 0x00, 0x68, 0x85, 0x01, 0x68, 0x68,
  111.    0x68, 0x68, 0xa9, 0x00, 0x48, 0xad, 0x21, 0xbf,
  112.    0xd0, 0x06, 0x20, 0x5c, 0xff, 0x4c, 0x1b, 0x00,
  113.    0x20, 0x0a, 0xbf, 0xad, 0x18, 0xbf, 0xcd, 0x19,
  114.    0xbf, 0xf0, 0x04, 0xa9, 0x01, 0xd0, 0x02, 0xa9,
  115.    0x00, 0x48, 0xa5, 0x01, 0x48, 0xa5, 0x00, 0x48,
  116.    0x60, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x01, 0x00,
  117.    0x00, 0x00, 0x00, 0x00, 0x3c, 0x00 };
  118.  
  119. static void Random(word EntryPoint)
  120. {
  121.   Pop();
  122.   Pop();
  123.   Push(rand()&0x7fff);
  124. }
  125.  
  126. static byte RandomSig[]=
  127. {  0x68, 0x85, 0x00, 0x68, 0x85, 0x01, 0x68, 0x68,
  128.    0x68, 0x68, 0xa0, 0x07, 0x0e, 0x39, 0x00, 0x08,
  129.    0x2e, 0x3a, 0x00, 0x2e, 0x3b, 0x00, 0x2e, 0x3c,
  130.    0x00, 0x30, 0x05, 0x28, 0x10, 0x08, 0x30, 0x03,
  131.    0x28, 0x30, 0x03, 0xee, 0x39, 0x00, 0x88, 0xd0,
  132.    0xe3, 0xad, 0x39, 0x00, 0x4a, 0x48, 0xad, 0x3b,
  133.    0x00, 0x48, 0xa5, 0x01, 0x48, 0xa5, 0x00, 0x48,
  134.    0x60, 0x5a, 0xb2, 0xf6, 0x93, 0x00, 0x00, 0x00,
  135.    0x33, 0x00, 0x31, 0x00, 0x30, 0x00, 0x2f, 0x00,
  136.    0x24, 0x00, 0x20, 0x00, 0x1d, 0x00, 0x07, 0x00,
  137.    0x00, 0x00, 0x00, 0x00, 0x54, 0x00 };
  138.  
  139. static byte TreeSearchSig[]=
  140. { 0x68, 0x85, 0x84, 0x68, 0x85, 0x85, 0x68, 0x68, 0x68, 0x68,
  141.   0x68, 0x85, 0x82, 0x68, 0x85, 0x83, 0x68, 0x85, 0x7e, 0x68,
  142.   0x85, 0x7f, 0x68, 0x85, 0x80, 0x68, 0x85, 0x81, 0xa2, 0x08,
  143.   0xa0, 0xff, 0xca, 0x30, 0x37, 0xc8, 0xb1, 0x82, 0xd1, 0x80,
  144.   0xf0, 0xf6, 0x30, 0x17, 0xa0, 0x08, 0xb1, 0x80, 0xaa, 0xc8,
  145.   0xb1, 0x80, 0xc9, 0x00, 0xd0, 0x04, 0xe0, 0x00, 0xf0, 0x2c,
  146.   0x86, 0x80, 0x85, 0x81, 0x4c, 0x1c };
  147.  
  148. #ifdef TURTLEGRAPHICS
  149. extern void TurtleGraphics(word EntryPoint);
  150. static byte TurtleSig[16]="TURTLEGRAPHICS::";
  151. #endif
  152.  
  153. extern void LongInt(word EntryPoint);
  154. static byte LongIntSig[]=
  155. { 0x68, 0x85, 0x76, 0x68, 0x85, 0x77, 0x68, 0xaa,
  156.   0x68, 0xbd, 0x16, 0x00, 0x85, 0x78, 0xbd, 0x17,
  157.   0x00, 0x85, 0x79, 0x6c, 0x78, 0x00, 0xa2, 0x00,
  158.   0x4d, 0x02, 0x7a, 0x02, 0xd1, 0x00, 0xad, 0x02,
  159.   0xc3, 0x03, 0x03, 0x06, 0x1f, 0x05, 0xe0, 0x00,
  160.   0x03, 0x05, 0x7c, 0x05, 0xe6, 0x76, 0xd0, 0x02,
  161.   0xe6, 0x77, 0x6c, 0x76, 0x00, 0xa9, 0x05, 0x6c,
  162.   0x00, 0x00, 0xa9, 0x0d, 0x6c, 0x00, 0x00, 0xa9,
  163.   0x06, 0x6c, 0x00, 0x00, 0x68, 0x85, 0x7a, 0x68,
  164.   0x85, 0x7b, 0x68, 0x85, 0x81, 0xc6, 0x81, 0x06,
  165.   0x81, 0x68, 0x68, 0x85, 0x83, 0x68, 0xba, 0xe8,
  166.   0xbd, 0x00, 0x01, 0xd0, 0x05, 0xe8, 0xc6, 0x81,
  167.   0xd0, 0xf6, 0x86, 0x7d, 0x8a, 0x18, 0x65, 0x81,
  168.   0xaa, 0xca, 0x86, 0x7f, 0xe8, 0xbd, 0x00, 0x01,
  169.   0x85, 0x80, 0xc6, 0x80, 0x06, 0x80, 0xe8, 0xe8,
  170.   0xbd, 0x00, 0x01, 0x85, 0x82, 0xe8, 0xe8, 0xbd,
  171.   0x00, 0x01, 0xd0, 0x05, 0xe8, 0xc6, 0x80, 0xd0,
  172.   0xf6, 0x86, 0x7c, 0xca, 0x8a, 0x18, 0x65, 0x80,
  173.   0x85, 0x7e, 0xa5, 0x80, 0x38, 0xe5, 0x81, 0x85,
  174.   0x84, 0xe6, 0x7a, 0xd0, 0x02, 0xe6, 0x7b, 0x6c,
  175.   0x7a, 0x00, 0x68, 0x85, 0x86, 0x68, 0x68, 0x85,
  176.   0x80, 0x68, 0x68, 0x85, 0x82, 0x68, 0xa5, 0x80,
  177.   0x38, 0xe5, 0x86, 0x90, 0x0a, 0x0a, 0xaa, 0xca,
  178.   0x30, 0x0d, 0x68, 0xd0, 0x11, 0xf0, 0xf8, 0x0a,
  179.   0xaa, 0xa9, 0x00, 0x48, 0xe8, 0xd0, 0xfc, 0x48,
  180.   0xa5, 0x82, 0x48, 0x4c, 0x2c, 0x00, 0x4c, 0x35,
  181.   0x00, 0xba, 0xe8, 0xe8, 0xe8, 0xbd, 0x00, 0x01,
  182.   0x49, 0xff, 0x9d, 0x00, 0x01, 0x4c, 0x2c, 0x00,
  183.   0x68, 0x0a, 0x0a, 0xaa, 0x68, 0xa0, 0x03, 0xbd,
  184.   0x27, 0x01, 0x99, 0x28, 0x01, 0xca, 0x88, 0x10,
  185.   0xf6, 0x20, 0x44, 0x00, 0xa5, 0x80, 0x05, 0x81,
  186.   0xf0, 0x2e, 0xa5, 0x83, 0xc5, 0x82, 0xd0, 0x28,
  187.   0xc9, 0xff, 0xf0, 0x0c, 0xa5, 0x80, 0xc5, 0x81,
  188.   0xd0, 0x1e, 0xa6, 0x7c, 0xa4, 0x7d, 0xd0, 0x0a,
  189.   0xa5, 0x81, 0xc5, 0x80, 0xd0, 0x12, 0xa6, 0x7d,
  190.   0xa4, 0x7c, 0xbd, 0x00, 0x01, 0xd9, 0x00, 0x01,
  191.   0xd0, 0x06, 0xe8, 0xc8, 0xc6, 0x80, 0xd0, 0xf2,
  192.   0xea, 0xea, 0xea, 0xea, 0x4c, 0x3b, 0x01, 0xa6,
  193.   0x7e, 0x9a, 0xa9, 0x00, 0x48, 0xa9, 0x01, 0x48,
  194.   0x4c, 0x2c, 0x00, 0xa6, 0x7e, 0x9a, 0xa9, 0x00,
  195.   0x48, 0x48, 0xf0, 0xf4, 0x90, 0x05, 0xea, 0xea,
  196.   0x90, 0x05, 0xf0, 0x03, 0xb0, 0x05, 0xea, 0xea,
  197.   0xf0, 0x02, 0xb0, 0x03, 0xd0, 0x05, 0xea, 0xea,
  198.   0xf0, 0x05, 0xea, 0xea, 0xa6, 0x7e, 0x9a, 0xa9,
  199.   0x00, 0x48, 0x48, 0x48, 0x48, 0x48, 0xa9, 0x02,
  200.   0x48, 0x4c, 0x2c, 0x00, 0xa5, 0x81, 0x85, 0x85,
  201.   0xa4, 0x7f, 0xa6, 0x7e, 0xb9, 0x00, 0x01, 0x9d,
  202.   0x00, 0x01, 0xca, 0x88, 0xc6, 0x85, 0xd0, 0xf4,
  203.   0x9a, 0x46, 0x81, 0x90, 0x05, 0xa9, 0x00, 0x48,
  204.   0xe6, 0x81, 0x48, 0xa5, 0x83, 0x48, 0x48, 0xe6,
  205.   0x81, 0xa5, 0x81, 0x48, 0x4c, 0x2c, 0x00, 0xa4,
  206.   0x80, 0xa6, 0x84, 0x30, 0x06, 0xa4, 0x81, 0xa5,
  207.   0x80, 0x85, 0x81, 0x84, 0x85, 0xa4, 0x7f, 0xa6,
  208.   0x7e, 0x18, 0xf8, 0xb9, 0x00, 0x01, 0x7d, 0x00,
  209.   0x01, 0x9d, 0x00, 0x01, 0xca, 0x88, 0xc6, 0x85,
  210.   0xd0, 0xf1, 0xa5, 0x84, 0xf0, 0x18, 0x30, 0x08,
  211.   0x49, 0xff, 0x85, 0x84, 0xe6, 0x84, 0x8a, 0xa8,
  212.   0xb9, 0x00, 0x01, 0x69, 0x00, 0x9d, 0x00, 0x01,
  213.   0xca, 0x88, 0xe6, 0x84, 0xd0, 0xf2, 0xd8, 0x9a,
  214.   0x90, 0x05, 0xa9, 0x01, 0x48, 0xe6, 0x81, 0xa5,
  215.   0x82, 0x85, 0x83, 0x4c, 0x81, 0x01, 0xa5, 0x80,
  216.   0xc5, 0x81, 0xd0, 0x17, 0x85, 0x85, 0xa6, 0x7c,
  217.   0xa4, 0x7d, 0xbd, 0x00, 0x01, 0xd9, 0x00, 0x01,
  218.   0xd0, 0x09, 0xe8, 0xc8, 0xc6, 0x85, 0xd0, 0xf2,
  219.   0x4c, 0x5c, 0x01, 0xb0, 0x0a, 0xa6, 0x7e, 0xa4,
  220.   0x7f, 0xa5, 0x80, 0x85, 0x85, 0xd0, 0x08, 0xa6,
  221.   0x7f, 0xa4, 0x7e, 0xa5, 0x81, 0x85, 0x85, 0x38,
  222.   0xf8, 0xb9, 0x00, 0x01, 0xfd, 0x00, 0x01, 0x99,
  223.   0x00, 0x01, 0xca, 0x88, 0xc6, 0x85, 0xd0, 0xf1,
  224.   0xb0, 0x0b, 0xb9, 0x00, 0x01, 0xe9, 0x00, 0x99,
  225.   0x00, 0x01, 0x88, 0x90, 0xf5, 0xd8, 0xc4, 0x7f,
  226.   0xb0, 0x0d, 0xa5, 0x86, 0xf0, 0x06, 0xa5, 0x83,
  227.   0x49, 0xff, 0x85, 0x83, 0x4c, 0x6c, 0x01, 0xa6,
  228.   0x7f, 0x9a, 0x4c, 0x2c, 0x00, 0x20, 0x44, 0x00,
  229.   0xa5, 0x80, 0x05, 0x81, 0xd0, 0x03, 0x4c, 0x5c,
  230.   0x01, 0xa5, 0x80, 0xd0, 0x03, 0x4c, 0x6c, 0x01,
  231.   0xa5, 0x81, 0xd0, 0x06, 0xa6, 0x7f, 0x9a, 0x4c,
  232.   0x2c, 0x00, 0xa5, 0x82, 0x45, 0x83, 0x30, 0x03,
  233.   0x4c, 0x97, 0x01, 0xa9, 0x00, 0x85, 0x86, 0x4c,
  234.   0xe6, 0x01, 0x20, 0x44, 0x00, 0xa5, 0x80, 0x05,
  235.   0x81, 0xd0, 0x03, 0x4c, 0x5c, 0x01, 0xa5, 0x80,
  236.   0xd0, 0x09, 0xa5, 0x83, 0x49, 0xff, 0x85, 0x83,
  237.   0x4c, 0x6c, 0x01, 0xa5, 0x81, 0xd0, 0x06, 0xa6,
  238.   0x7f, 0x9a, 0x4c, 0x2c, 0x00, 0xa5, 0x82, 0x45,
  239.   0x83, 0x10, 0x03, 0x4c, 0x97, 0x01, 0xa9, 0x01,
  240.   0x85, 0x86, 0x4c, 0xe6, 0x01, 0x20, 0x44, 0x00,
  241.   0xa5, 0x80, 0xf0, 0x04, 0xa5, 0x81, 0xd0, 0x03,
  242.   0x4c, 0x5c, 0x01, 0xa5, 0x82, 0x45, 0x83, 0x85,
  243.   0x83, 0xba, 0x86, 0x86, 0xa5, 0x80, 0x85, 0x89,
  244.   0xe6, 0x89, 0x18, 0x65, 0x81, 0x85, 0x88, 0x8a,
  245.   0x38, 0xe5, 0x88, 0x85, 0x87, 0xe5, 0x88, 0xaa,
  246.   0x9a, 0xa4, 0x88, 0xa6, 0x86, 0xa9, 0x00, 0x9d,
  247.   0x00, 0x01, 0xca, 0x88, 0xd0, 0xf9, 0xa5, 0x86,
  248.   0x85, 0x8d, 0xa5, 0x88, 0x85, 0x8e, 0xa5, 0x81,
  249.   0x85, 0x8a, 0xa5, 0x7f, 0x85, 0x8b, 0xf8, 0xa9,
  250.   0x00, 0x85, 0x8c, 0xa4, 0x88, 0xa6, 0x87, 0x9d,
  251.   0x00, 0x01, 0xca, 0x88, 0xd0, 0xf9, 0xa6, 0x8b,
  252.   0xbd, 0x00, 0x01, 0xa2, 0x06, 0xdd, 0x77, 0x03,
  253.   0x90, 0x03, 0xfd, 0x77, 0x03, 0x26, 0x8c, 0xca,
  254.   0x10, 0xf3, 0xa6, 0x7e, 0xa4, 0x87, 0xa5, 0x80,
  255.   0x85, 0x85, 0xbd, 0x00, 0x01, 0x99, 0x00, 0x01,
  256.   0xca, 0x88, 0xc6, 0x85, 0xd0, 0xf4, 0x46, 0x8c,
  257.   0x90, 0x18, 0xa6, 0x87, 0xa4, 0x8d, 0xa5, 0x8e,
  258.   0x85, 0x85, 0x18, 0xbd, 0x00, 0x01, 0x79, 0x00,
  259.   0x01, 0x99, 0x00, 0x01, 0xca, 0x88, 0xc6, 0x85,
  260.   0xd0, 0xf1, 0xa5, 0x8c, 0xf0, 0x13, 0xa6, 0x87,
  261.   0xa4, 0x89, 0xbd, 0x00, 0x01, 0x7d, 0x00, 0x01,
  262.   0x9d, 0x00, 0x01, 0xca, 0x88, 0xd0, 0xf3, 0xf0,
  263.   0xcd, 0xc6, 0x8d, 0xc6, 0x8e, 0xc6, 0x8b, 0xc6,
  264.   0x8a, 0xd0, 0x8c, 0xd8, 0xa5, 0x86, 0x85, 0x7f,
  265.   0xa5, 0x88, 0x85, 0x81, 0x4c, 0x6c, 0x01, 0x01,
  266.   0x02, 0x04, 0x08, 0x16, 0x32, 0x64, 0xa9, 0x00,
  267.   0x85, 0x89, 0xa5, 0x7c, 0x18, 0x65, 0x88, 0xaa,
  268.   0xca, 0xe4, 0x7e, 0xf0, 0x02, 0xb0, 0x32, 0x86,
  269.   0x86, 0xf8, 0x38, 0xa6, 0x86, 0xa4, 0x87, 0xa5,
  270.   0x88, 0x85, 0x85, 0x90, 0x13, 0xbd, 0x00, 0x01,
  271.   0xf9, 0x00, 0x01, 0x9d, 0x00, 0x01, 0xca, 0x88,
  272.   0xc6, 0x85, 0xd0, 0xf1, 0xe6, 0x89, 0xd0, 0xe3,
  273.   0xbd, 0x00, 0x01, 0x79, 0x00, 0x01, 0x9d, 0x00,
  274.   0x01, 0xca, 0x88, 0xc6, 0x85, 0xd0, 0xf1, 0xc6,
  275.   0x89, 0xd8, 0x60, 0x20, 0x44, 0x00, 0xa5, 0x81,
  276.   0xd0, 0x03, 0x4c, 0x3f, 0x00, 0xa5, 0x80, 0xc5,
  277.   0x81, 0xd0, 0x16, 0xa6, 0x7c, 0xa4, 0x7d, 0xa5,
  278.   0x80, 0x85, 0x85, 0xbd, 0x00, 0x01, 0xd9, 0x00,
  279.   0x01, 0xd0, 0x06, 0xe8, 0xc8, 0xc6, 0x85, 0xd0,
  280.   0xf2, 0xb0, 0x03, 0x4c, 0x5c, 0x01, 0xa5, 0x82,
  281.   0x45, 0x83, 0x85, 0x83, 0xa9, 0x00, 0xc6, 0x7c,
  282.   0xa4, 0x7c, 0x99, 0x00, 0x01, 0xe6, 0x80, 0xa6,
  283.   0x7d, 0xca, 0x9a, 0x48, 0xe6, 0x81, 0xba, 0x86,
  284.   0x8b, 0x8a, 0x38, 0xe5, 0x80, 0x85, 0x8c, 0x85,
  285.   0x8a, 0xe5, 0x81, 0xaa, 0x9a, 0xa5, 0x81, 0x85,
  286.   0x8f, 0x85, 0x91, 0x85, 0x90, 0xa6, 0x7f, 0xa4,
  287.   0x8c, 0x86, 0x8d, 0x84, 0x8e, 0xa5, 0x81, 0x85,
  288.   0x85, 0xbd, 0x00, 0x01, 0x99, 0x00, 0x01, 0xca,
  289.   0x88, 0xc6, 0x85, 0xd0, 0xf4, 0xa2, 0x01, 0x86,
  290.   0x92, 0xa6, 0x7d, 0xbd, 0x00, 0x01, 0x29, 0xf0,
  291.   0xf0, 0x13, 0xa9, 0x00, 0x85, 0x92, 0x48, 0xe6,
  292.   0x8f, 0xa5, 0x8f, 0x85, 0x90, 0xa5, 0x8c, 0x85,
  293.   0x8d, 0xa5, 0x7f, 0x85, 0x8e, 0xa9, 0x04, 0x85,
  294.   0x85, 0x18, 0xa6, 0x8c, 0xa4, 0x8f, 0x3e, 0x00,
  295.   0x01, 0xca, 0x88, 0xd0, 0xf9, 0xc6, 0x85, 0xd0,
  296.   0xf0, 0xa9, 0x00, 0x85, 0x93, 0xa5, 0x8e, 0x85,
  297.   0x87, 0xa5, 0x91, 0x85, 0x88, 0x20, 0x7e, 0x03,
  298.   0xa6, 0x86, 0xe4, 0x7e, 0xd0, 0x02, 0xe6, 0x93,
  299.   0xa5, 0x89, 0x85, 0x84, 0xa5, 0x8d, 0x85, 0x87,
  300.   0xa5, 0x90, 0x85, 0x88, 0x20, 0x7e, 0x03, 0xa5,
  301.   0x84, 0x0a, 0x0a, 0x0a, 0x0a, 0x05, 0x89, 0xe6,
  302.   0x8a, 0xa6, 0x8a, 0x9d, 0x00, 0x01, 0xe6, 0x7c,
  303.   0xa5, 0x93, 0xf0, 0xc9, 0xa5, 0x8a, 0x85, 0x7f,
  304.   0x38, 0xe5, 0x8c, 0x85, 0x81, 0xa5, 0x92, 0xd0,
  305.   0x14, 0xa9, 0x04, 0x85, 0x85, 0x18, 0xa6, 0x8c,
  306.   0xa4, 0x81, 0xe8, 0x7e, 0x00, 0x01, 0x88, 0xd0,
  307.   0xf9, 0xc6, 0x85, 0xd0, 0xf0, 0x4c, 0x6c, 0x01,
  308.   0xa9, 0x00, 0x85, 0x82, 0x85, 0x88, 0x85, 0x89,
  309.   0x85, 0x8a, 0x85, 0x8b, 0xa5, 0x87, 0x10, 0x14,
  310.   0x49, 0xff, 0x85, 0x87, 0xa5, 0x86, 0x49, 0xff,
  311.   0x85, 0x86, 0xe6, 0x86, 0xd0, 0x02, 0xe6, 0x87,
  312.   0xa9, 0xff, 0x85, 0x82, 0xa0, 0x10, 0xf8, 0x26,
  313.   0x86, 0x26, 0x87, 0xa2, 0x03, 0xb5, 0x88, 0x75,
  314.   0x88, 0x95, 0x88, 0xca, 0x10, 0xf7, 0x88, 0xd0,
  315.   0xee, 0xd8, 0x60, 0x68, 0x85, 0x86, 0x68, 0x85,
  316.   0x87, 0x20, 0xc8, 0x04, 0xa2, 0x03, 0xb5, 0x88,
  317.   0x48, 0xca, 0x10, 0xfa, 0x48, 0xa5, 0x82, 0x48,
  318.   0x48, 0xa9, 0x03, 0x48, 0x4c, 0x2c, 0x00, 0xba,
  319.   0xe8, 0x86, 0x7d, 0xbc, 0x00, 0x01, 0x88, 0x98,
  320.   0x0a, 0x85, 0x81, 0x8a, 0x18, 0x65, 0x81, 0x69,
  321.   0x05, 0x85, 0x7c, 0xaa, 0xbd, 0x00, 0x01, 0x85,
  322.   0x87, 0xca, 0xbd, 0x00, 0x01, 0x85, 0x86, 0x20,
  323.   0xc8, 0x04, 0xba, 0x8a, 0x38, 0xe9, 0x06, 0xaa,
  324.   0x9a, 0xe8, 0xa5, 0x81, 0x18, 0x69, 0x04, 0x85,
  325.   0x85, 0xa4, 0x7d, 0xb9, 0x00, 0x01, 0x9d, 0x00,
  326.   0x01, 0xe8, 0xc8, 0xc6, 0x85, 0xd0, 0xf4, 0xa4,
  327.   0x7c, 0xa2, 0x03, 0xb5, 0x88, 0x99, 0x00, 0x01,
  328.   0x88, 0xca, 0x10, 0xf7, 0x88, 0xa5, 0x82, 0x99,
  329.   0x00, 0x01, 0x88, 0x88, 0xa9, 0x03, 0x99, 0x00,
  330.   0x01, 0x4c, 0x2c, 0x00, 0x68, 0x85, 0x80, 0xc6,
  331.   0x80, 0x68, 0x68, 0x85, 0x82, 0x68, 0xa5, 0x80,
  332.   0x38, 0xe9, 0x03, 0x90, 0x0e, 0xaa, 0x68, 0xd0,
  333.   0x6f, 0x68, 0xd0, 0x6c, 0xca, 0x10, 0xf7, 0xa9,
  334.   0x02, 0x85, 0x80, 0xa9, 0x00, 0x85, 0x88, 0xa5,
  335.   0x80, 0xc9, 0x01, 0xf0, 0x06, 0x68, 0xd0, 0x58,
  336.   0x68, 0x85, 0x88, 0x68, 0x85, 0x89, 0x68, 0x85,
  337.   0x8a, 0xa9, 0x0f, 0x85, 0x85, 0x46, 0x88, 0x66,
  338.   0x89, 0x66, 0x8a, 0x66, 0x87, 0x66, 0x86, 0xa2,
  339.   0x02, 0xb5, 0x88, 0x10, 0x03, 0x38, 0xe9, 0x30,
  340.   0xa8, 0x29, 0x08, 0xf0, 0x03, 0x88, 0x88, 0x88,
  341.   0x94, 0x88, 0xca, 0x10, 0xec, 0xc6, 0x85, 0xd0,
  342.   0xdc, 0xa5, 0x8a, 0xd0, 0x23, 0x46, 0x87, 0x66,
  343.   0x86, 0xa5, 0x82, 0x10, 0x12, 0xa5, 0x87, 0x49,
  344.   0xff, 0x85, 0x87, 0xa5, 0x86, 0x49, 0xff, 0x85,
  345.   0x86, 0xe6, 0x86, 0xd0, 0x02, 0xe6, 0x87, 0xa5,
  346.   0x87, 0x48, 0xa5, 0x86, 0x48, 0x4c, 0x2c, 0x00,
  347.   0x4c, 0x35, 0x00, 0x68, 0x85, 0x86, 0x68, 0x68,
  348.   0x85, 0x88, 0x68, 0x85, 0x89, 0x68, 0x85, 0x80,
  349.   0xc6, 0x80, 0x06, 0x80, 0x68, 0xa0, 0x00, 0x68,
  350.   0x10, 0x05, 0xa9, 0x2d, 0xc8, 0x91, 0x88, 0x68,
  351.   0x68, 0xd0, 0x04, 0xc6, 0x80, 0xd0, 0xf9, 0xc9,
  352.   0x10, 0xb0, 0x0c, 0x09, 0x30, 0xc8, 0x91, 0x88,
  353.   0xc6, 0x80, 0xf0, 0x19, 0x30, 0x17, 0x68, 0xaa,
  354.   0x4a, 0x4a, 0x4a, 0x4a, 0x09, 0x30, 0xc8, 0x91,
  355.   0x88, 0x8a, 0x29, 0x0f, 0x09, 0x30, 0xc8, 0x91,
  356.   0x88, 0xc6, 0x80, 0xd0, 0xe9, 0xc4, 0x86, 0x90,
  357.   0x05, 0xf0, 0x03, 0x4c, 0x3a, 0x00, 0x98, 0xa0,
  358.   0x00, 0x91, 0x88, 0x4c, 0x2c, 0x00, 0x00, 0x00,
  359.   0x56, 0x06, 0x53, 0x06, 0x4e, 0x06, 0x4e, 0x06,
  360.   0x4e, 0x06, 0x4e, 0x06, 0x4e, 0x06, 0x4e, 0x06,
  361.   0x4e, 0x06, 0x4e, 0x06, 0x4e, 0x06, 0x4e, 0x06,
  362.   0x4e, 0x06, 0xae, 0x05, 0xad, 0x05, 0xa0, 0x05,
  363.   0x98, 0x05, 0x97, 0x05, 0x92, 0x05, 0x59, 0x05,
  364.   0x4f, 0x05, 0x20, 0x05, 0xf7, 0x04, 0xaa, 0x04,
  365.   0x8f, 0x04, 0x4d, 0x04, 0x49, 0x04, 0x48, 0x04,
  366.   0x41, 0x04, 0x3c, 0x04, 0x34, 0x04, 0x2d, 0x04,
  367.   0x28, 0x04, 0x27, 0x04, 0x20, 0x04, 0x15, 0x04,
  368.   0x0d, 0x04, 0x06, 0x04, 0x01, 0x04, 0x00, 0x04,
  369.   0xf7, 0x03, 0xa4, 0x03, 0xa1, 0x03, 0x41, 0x03,
  370.   0xf4, 0x02, 0xef, 0x02, 0xd0, 0x02, 0x48, 0x02,
  371.   0x33, 0x02, 0xfc, 0x01, 0xba, 0x01, 0xa9, 0x01,
  372.   0x88, 0x01, 0x50, 0x01, 0xce, 0x00, 0xcd, 0x00,
  373.   0x7c, 0x00, 0x76, 0x00, 0x3a, 0x00, 0x00, 0x00,
  374.   0x00, 0x00, 0xda, 0x06};
  375.  
  376. struct
  377. {
  378.   byte    *Sig;
  379.   int    SigLen;
  380.   void    (*Proc)(word);
  381. } Routines[]={ { IdSearchSig, sizeof(IdSearchSig),    IdSearch},
  382.            { TreeSearchSig, sizeof(TreeSearchSig),    TreeSearch},
  383. #ifdef TURTLEGRAPHICS
  384.            { TurtleSig, sizeof(TurtleSig),        TurtleGraphics},
  385. #endif
  386.            { RandomizeSig1, sizeof(RandomizeSig1),    Randomize},
  387.            { RandomizeSig2, sizeof(RandomizeSig2),    Randomize},
  388.            { RandomSig, sizeof(RandomSig),        Random},
  389.            { KeypressSig, sizeof(KeypressSig),    Keypress},
  390.            { LongIntSig, sizeof(LongIntSig),    LongInt}
  391. };
  392.  
  393. #define NUM_ROUTINES (sizeof(Routines)/sizeof(Routines[0]))
  394.  
  395. static inline word SelfRelPtr(word Addr)
  396. {
  397. #ifdef WORD_MEMORY
  398.   return(Addr-MemRd(Addr)/2);
  399. #else
  400.   return(Addr-MemRd(Addr));
  401. #endif
  402. }
  403.  
  404. static inline word ProcBase(word JTab)
  405. {
  406.   PointerCheck(JTab);
  407.   return (SelfRelPtr(WordIndexed(JTab,-1)));
  408. }
  409.  
  410. void ProcessNative(word JTab)
  411. {
  412.   word EntryPoint=ProcBase(JTab);
  413.   int i;
  414.   for (i=0; i<NUM_ROUTINES; i++)
  415.     {
  416.       int j;
  417.       for (j=0; j<Routines[i].SigLen; j++)
  418.     if (MemRdByte(EntryPoint,j)!=Routines[i].Sig[j])
  419.       goto next;
  420.       Routines[i].Proc(EntryPoint);
  421.       return;
  422.     next:
  423.       ;
  424.     }
  425.  
  426. #ifdef XXX
  427.   TermClose();
  428.   for (i=0;WordIndexed(EntryPoint,i)<JTab; i++)
  429.     {
  430.       word w=MemRd(WordIndexed(EntryPoint,i));
  431.       printf(" 0x%02x, 0x%02x,", w&0xff, w>>8);
  432.       if ((i&3)==3)
  433.     printf("\n");
  434.     }
  435.   printf("\n");
  436.   panic("ProcessNative: unsupported native routine at 0x%04x", EntryPoint);
  437. #else
  438.   XeqError(XNOTIMP);
  439. #endif
  440. }
  441.  
  442.